<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use DateTimeInterface;

class Domainlist extends Model
{
    protected $table = 'domain_list';
    protected $primaryKey = 'id';
    
    public static function saleDomainList()
    {
        return self::select("domain","id")->where("status",1)->orderBy("id","ASC")->take(5)->get();
    }

    public static function saleDomain()
    {
        return self::select("domain","id")->where("status",1)->orderBy("id","ASC")->first();
    }

    public static function userDomain($openid)
    {
        return self::where("openid",$openid)->orderBy("id","DESC")->first();
    }
    
    public static function domainDetial($domain)
    {
        return self::where("domain",$domain)->first();
    }

    public static function domainSaled($domain,$openid)
    {
        return self::where("domain",$domain)->update(["openid"=>$openid,"status"=>2]);
    }

    public static function domainListBack($domain)
    {
        return self::where("domain",$domain)->update(["openid"=>"","status"=>1]);
    }

    public static function shortLinkUpdate($openid,$short_id,$name,$link,$end_time,$group_id,$deadline,$domain)
    {
        return self::where("openid",$openid)->where("short_id",$short_id)->update(["name"=>$name,"link"=>$link,"end_time"=>$end_time,"group_id"=>$group_id,"deadline"=>$deadline,"domain"=>$domain]);
    }

    public static function shortLinkCreate($openid,$name,$link,$end_time,$group_id,$deadline,$domain)
    {
        return self::insertGetId(["openid"=>$openid,"name"=>$name,"link"=>$link,"end_time"=>$end_time,"group_id"=>$group_id,"deadline"=>$deadline,"domain"=>$domain,"created_at"=>time()]);
    }
}